<template>
  <div>
    <el-table :data="page" stripe @selection-change="handleSelectionChange" >
      <el-table-column type="selection" width="55" />
      <el-table-column label="条码" prop="barCode" />
      <el-table-column label="名称" prop="name" />
      <el-table-column label="规格" prop="standard" />
      <el-table-column label="型号" prop="model" />
      <el-table-column label="单位" prop="materialUnit" />
      <el-table-column label="数量" prop="operNumber" />
      <el-table-column label="单价" prop="unitPrice" />
      <el-table-column label="金额" prop="allPrice" />
      <el-table-column label="税率(%)" prop="taxRate" />
      <el-table-column label="税额" prop="taxMoney" />
      <el-table-column label="价税合计" prop="taxLastMoney" />
      <el-table-column label="备注" prop="remark" />
    </el-table>
    <!-- 按钮 -->
    <form>
        <el-row :gutter="20" style="height: 30px">
          <el-col :span="24" :offset="0">
              <el-form-item style="position: fixed;bottom: 130px; right: 330px;">
                  <el-button @click="close">关闭</el-button>
                  <el-button type="primary" @click="saveSelected">确定</el-button>
              </el-form-item>
          </el-col>
        </el-row>
    </form>
  </div>
</template>

<script setup>
import { ref, defineEmits, defineProps } from 'vue';
import { ElMessage } from 'element-plus';
import request from '@/api/request';

let emits = defineEmits(['close', 'items']); 

let props = defineProps(["data"]);

//接收headerId
let headerId = ref(props.data);
//选中的子单据
let selectedItems = ref([]);
//查询到的子单据
let page = ref([]);

let handleSelectionChange = (val) => {  
  selectedItems.value = val;
};

//传值
let saveSelected = () => {
  if (selectedItems.value.length === 0) {
    ElMessage.warning('抱歉，请选择单据明细！');
    return;
  }
  emits('items', selectedItems.value);
  emits('close');
};

//初始化
let init = () =>{
    request({
        url: '/purchase/order/findItems',
        method: "get",
        params: {
          headerId: headerId.value,
        }
    }).then(res => {
        page.value = res.data
    })
}
init();

let close = () => {
  emits('close');
};
</script>
<style scoped></style>